#!/usr/bin/env python3
import sqlite3
import os

# 连接到容器内的数据库
db_path = './openmemory.db'
print(f"检查数据库: {db_path}")
print(f"文件存在: {os.path.exists(db_path)}")

if os.path.exists(db_path):
    conn = sqlite3.connect(db_path)
    cursor = conn.cursor()
    
    # 查看所有表
    cursor.execute('SELECT name FROM sqlite_master WHERE type="table"')
    tables = cursor.fetchall()
    print("表:", [t[0] for t in tables])
    
    # 查看apps表
    try:
        cursor.execute('SELECT id, name FROM apps ORDER BY created_at')
        apps = cursor.fetchall()
        print("应用:")
        for app in apps:
            print(f"  - ID: {app[0]}, 名称: {app[1]}")
    except Exception as e:
        print("查询apps表错误:", e)
    
    # 查看memories表
    try:
        cursor.execute('SELECT COUNT(*) FROM memories')
        mem_count = cursor.fetchone()[0]
        print(f"记忆数量: {mem_count}")
    except Exception as e:
        print("查询memories表错误:", e)
    
    conn.close()
else:
    print("数据库文件不存在")